/**
 * 公用配置
 */
(function($){
	var NeioConfig = function(){};
	
	/**
	 * 获取Config 对象
	 */
	NeioConfig.prototype.getNeioConfig = function(){
		return mConfig;
	}
	
	/**
	 * 存入数据
	 * @param {Object} key 存数据是使用的Key 再COnfig中获取后传入
	 * @param {Object} param 存入的参数 建议使用String 类型
	 */
	NeioConfig.prototype.setStorage = function(key,param){
		localStorage.setItem(key,param)
	}
	
	/**
	 * 取出数据
	 * @param {Object} key 存数据是使用的Key 再COnfig中获取后传入
	 */
	 NeioConfig.prototype.getStorage = function(key){
		let value = localStorage.getItem(key)
		return value;
	}
	
	/**
	 * 获取变压器类型列表
	 */
	NeioConfig.prototype.getTransFormer = function(){
		let value = localStorage.getItem('transFormerCodeList')
		return value;
	}
	
	NeioConfig.prototype.workType = function(){
		let typeList = [
		{"text":"场站交接班","value":"0201","url":"/app/statistical/queryChangeShift"},
		{"text":"蓄电池","value":"0101","url":"/app/statistical/queryStorBatterySearch"},
		{"text":"场用电切换","value":"0102","url":"/app/statistical/queryDeviceSwitchSearch "},
		{"text":"UPS设备切换","value":"0103","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"事故照明切换","value":"0104","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"主变风冷切换","value":"0105","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"直流设备切换","value":"0106","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"消防设备切换","value":"0107","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"通信设备切换","value":"0108","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"柴油发电机","value":"0109","url":"/app/statistical/queryDeviceSwitchSearch"},
		{"text":"工器具检查","value":["0110","0207"],"url":"/app/statistical/queryToolsSearch"},
		{"text":"安全设施检查","value":"0111","url":"/app/statistical/querySafeDeviceSearch"},
		{"text":"差动电流","value":"0112","url":"/app/statistical/queryDiffCurrentSearch"},
		{"text":"生活消防水设备检查","value":"0113","url":"/app/statistical/queryLifeWaterSearch"},
		{"text":"设备红外","value":"0114","url":"/app/statistical/queryInfraredSearch"},
		{"text":"网络安全设备","value":"0115","url":"/app/statistical/queryNetSafeDeviceSearch"},//待定
		{"text":"主变压器铁芯、夹件","value":"0116","url":"/app/statistical/queryMainTransCore"},
		{"text":"避雷器动作记录","value":"0117","url":"/app/statistical/queryArresterSearch"},
		{"text":"钥匙借用归还","value":"0202,0203","url":"/app/statistical/queryKeyBorrowRepaySearch"},
		{"text":"涉网设备投退","value":"0204,0209","url":"/app/statistical/queryNetDevicesSearch"},
		{"text":"保护压板投退","value":"0205,0208","url":"/app/statistical/queryProtectPieceSearch"},
		{"text":"变压器有载调压","value":"0206","url":"/app/statistical/queryTansformSearch"},
		// {"text":"工器具日常检查记录","value":"0207"},
		
		{"text":"培训记录","value":"01","url":"/app/statistical/queryTranEducationSearch"},
		{"text":"安全活动","value":"00","url":"/app/statistical/queryTranEducationSearch"},
		{"text":"应急演练","value":"10","url":"/app/statistical/queryDrillSearch"},
		{"text":"反事故演习","value":"11","url":"/app/statistical/queryDrillSearch"},
		{"text":"事故预想记录","value":"12","url":"/app/statistical/queryDrillSearch"}
		];

		return typeList;
		
		
	}
	
	/**
	 * transForm 数据
	 * @param {Object} param 后台返回的参数
	 * @param {Object} dataStatus 数据状态 1 新增修改 0 无效/删除
	 * @param {Object} edit 操作类型 0 新增 1 编辑
	 */
	NeioConfig.prototype.getTransForm = function(param,dataStatus,edit){
		let paramData = {};
		paramData.transForm = {};//数据中最外层的人员组织信息
		paramData.infoListParam = [];//内部表单List
		//人员信息 获取
		let persionData = JSON.parse(localStorage.getItem("neiosUser"));
		//获取 uuid 
		let uuid = mui.neiosCommon.getUuidv4();
		paramData.transForm.status = "21"; //状态 固定传21
		paramData.transForm.operateStaffCodeName = param.operateStaffCodeName;//操作人工号姓名-当前人
		paramData.transForm.operateStaffCode = param.operateStaffCode == undefined ? persionData.id : param.operateStaffCode;//操作人工号
		paramData.transForm.operateStaffName = param.operateStaffName == undefined ? persionData.name : param.operateStaffName;//操作人姓名

		paramData.transForm.tutelageStaffCode = param.tutelageStaffCode;//监护人工号
		paramData.transForm.tutelageStaffName = param.tutelageStaffName;//监护人姓名
		paramData.transForm.tutelageStaffCodeName = param.tutelageStaffCodeName;//监护人工号姓名
		paramData.transForm.transOperateId = param.transOperateId;//主键Id
		paramData.transForm.type = edit == 0 ? "" : "edit";//如果是新增数据就不传，如果是编辑数据就传edit
		paramData.transForm.modifyBy = persionData.userId;//当前登陆人工号
		paramData.transForm.modifyStaffName = persionData.name;//当前登录人姓名
		paramData.transForm.areaCompanyCode = persionData.companyCode;//分公司编码--新增时候传，编辑不传
		paramData.transForm.stationCode = persionData.stationCode;//场站编码--新增时候传，编辑不传
		paramData.transForm.dataStatus = '1';////数据状态1有效0无效
		paramData.transForm.dataSource = (edit == '0'? "NEIOS_APP"+localStorage.getItem("currVersion"):'');//固定值--新增时候传，编辑不传
		paramData.transForm.client = (edit == '0'? "NEIOS":'');//固定值--新增时候传，编辑不传
		paramData.transForm.createBy = persionData.userId;//当前登录人编号--新增时候传，编辑不传
		paramData.transForm.createStaffName = persionData.name;//当前登陆人姓名--新增时候传，编辑不传
		paramData.transForm.newAreaCode  = persionData.companyNewCode;//新能源分公司编码
		paramData.transForm.newStationCode  = localStorage.getItem('neiosStationCode') == null ? '1020' : localStorage.getItem('neiosStationCode');// persionData.stationNewCode;//新能源场站编码
		// that.paramData = paramData;
		param.dataStatus = dataStatus;
		paramData.infoListParam.push(param)
		
		return paramData;
	}
	
	//获取 UUID
	function getUuidv4() {
		let uuid = mui.neiosCommon.getUuidv4();
		return uuid;
	}
	
	//设置涉网设备数据
	let netData = [];
	let type ;//投入或退出
	let newData = [];//涉网设备 List
	NeioConfig.prototype.setNetData = function(data,type,fun){
		netData = [];
		newData = [];
		netData = netData.concat(data);
		type = type;
		devideCodeCheck(fun,type);
	}
	
	//验证当前设备是否可以进行投退
	function devideCodeCheck(fun,type){
		console.log("|||||||||||||||||||||||||||||||||||||||||||||||||||||||")
			let netChildData = {};//新的涉网设备字表（向其中添加 deviceInfoId）
			if(netData.length <= 0) return
			let typetext = type == "in" ? "投入" : "退出"
			let persionData = JSON.parse(localStorage.getItem("neiosUser"));
			let param = {};
			netChildData = netData[0];
			param.deviceCode = netData[0].deviceCode;
			param.operateType = type == "in" ? "1" : "0";//投入1退出0
			param.inOperateId = netData[0].inOperateId == undefined ? "" : netData[0].inOperateId;//投入的传,有就传没有就空
			param.outOperateId = netData[0].outOperateId == undefined ? "" : netData[0].outOperateId ;//退出的传,有就传没有就空
			param.operateStaffCode = persionData.userId;//当前登陆人
			param.stationCode = localStorage.getItem('neiosStationCode') == null ? '1020' : localStorage.getItem('neiosStationCode');
			// param.stationCode = "50322817";//需要换成新的（PC端错误）
			let url = mConfig.URL.checkDeviceValidate;
			console.log("校验参数："+JSON.stringify(param))
			mui.neiosRequst.httpRequst(url,param,function(ret){
				console.log("校验返回："+JSON.stringify(ret))
				if(ret.code == 0){
					if(ret.isRepeat == false){
						if(ret.deviceInfoId != ""){
							netChildData.deviceInfoId = ret.deviceInfoId
						}
						newData.push(netChildData);
						netData.splice(0,1)
						if(netData.length > 0){
							devideCodeCheck(fun,type)
						}else{
							fun(ret.isRepeat,newData)
						}
					}else{
						mui.alert("设备编号"+netData[0].deviceCode+"无法进行" + typetext)
					}
				}
				if( ret.code == 1){
					mui.toast(ret.msg)
				}
			},function(err){
				console.log("失败回掉："+JSON.stringify(err))
			})
	}
	
	
	/**
	 * 涉网设备投退 数据
	 * @param {Object} param 后台返回的参数
	 * @param {Object} dataStatus 数据状态 1 新增修改 0 无效/删除
	 * @param {Object} edit 操作类型 0 新增 1 编辑
	 */
	NeioConfig.prototype.getDevoice = function(item,dataStatus,edit,that){
		//主数据
		let param = {};
		param.netDeviceOperate = {};
		param.netDeviceInfo = [];
		let persionData = JSON.parse(localStorage.getItem("neiosUser"));
		param.netDeviceOperate.networkDeviceOperateId = item.outOperateId;//主键
		param.netDeviceOperate.workId = item.outWorkId;// that.uuidv4();//保存没有
		param.netDeviceOperate.workDesc = "对涉网设备的投入信息进行修改";//保存没有 - 对涉网设备的投入信息进行提交
		param.netDeviceOperate.areaCompanyCode = persionData.companyCode;//分公司code
		param.netDeviceOperate.newAreaCode = persionData.companyNewCode;//新能源分公司code
		param.netDeviceOperate.stationCode =  persionData.stationCode;//localStorage.getItem('neiosStationCode');//场站code
		param.netDeviceOperate.newStationCode = localStorage.getItem('neiosStationCode');//新能源场站code
		param.netDeviceOperate.operateStaffCode = persionData.userId;//当前登陆人ID
		param.netDeviceOperate.operateStaffName = persionData.name;//当前登陆人Name
		param.netDeviceOperate.operateType = "1";//1代表投入 固定值
		param.netDeviceOperate.operateTime = "";// <<例子里没传>>
		param.netDeviceOperate.remark = "";// <<例子里没传>>
		param.netDeviceOperate.client = (edit == '0'? "NEIOS":'');//固定值--新增时候传，编辑不传
		param.netDeviceOperate.dataSource = (edit == '0'? "NEIOS_APP"+localStorage.getItem("currVersion"):'');
		param.netDeviceOperate.status = "32";//提交 32 保存 21
		param.netDeviceOperate.dataStatus = dataStatus;//固定值 1 有效 0 无效
		param.netDeviceOperate.createBy = persionData.userId;//创建人Id
		param.netDeviceOperate.createStaffName = persionData.name;//创建人姓名
		param.netDeviceOperate.createDate = "";//创建时间
		param.netDeviceOperate.modifyBy = persionData.userId;//当前登陆人工号
		param.netDeviceOperate.modifyStaffName = persionData.name;//当前登陆人姓名
		param.netDeviceOperate.modifyDate = "";//修改时间
		
		item.dataStatus = dataStatus;
		
		let data = item;
		param.netDeviceInfo.push(data);
		console.log(JSON.stringify(param))
		return param;
	}
	
	//变压器有载调压 提交功能 列表验证
	let transFormList = {
		isLumpFirst:false,
		isLumpFirstAdd:true,
		selectText:"请选择变压器",
		transType:"请选择变压器",
		transTypeText:"请选择变压器",
		deviceCode:"请输入设备编号",
		beforeAdjustInfo:"请输入分头调节前电压",
		afterAdjustInfo:"请输入分头调节后电压",
		operateCount:"请输入累计次数",
		beforeI:"请输入调前电流",
		afterI:"请输入调后电流",
		highV:"请输入两侧高压",
		lowV:"请输入两侧低压",
		beforeHighV:"请输入调节前高压",
		afterHighV:"请输入调节后高压",
		beforeLowV:"请输入调节前低压",
		afterLowV:"请输入调节后低压",
		remark:"备注",
	}
	/**
	 * 变压器有载调压 
	 * @param {Object} data list
	 */
	NeioConfig.prototype.verificationData = function(data){
		for(let position in data){
			
			let mPos = parseInt(position)+1;
			for(let key in transFormList){
					if(data[position][key] == undefined || data[position][key] === ""){
						if(key != "remark" && key != "isLumpFirst" && key != "isLumpFirstAdd"){
							mui.alert("表单"+mPos+":"+transFormList[key])
							return false;
						}
					}
			}
		}
		return true;
	}
	
	//涉网设备投退非空验证
	//投入
	let netWorkInList = {
		isLumpFirst:false,
		isLumpFirstAdd:true,
		deviceCode:"请输入设备编号",//设备编号
		deviceName:"请输入设备名称",//设备名称
		inTime:"请选择投入时间",//投入时间
		commandContent:"请输入调令内容",//调令内容
		areaCenterCommand:"",//区调/中调令
		monthOutCount:"请输入本月此装置退出次数",//本月此装置退出次数(累计值)
		deviceInfoId:"",
	}
	
	//涉网设备退出
	let netWorkOutList = {
		isLumpFirst:false,
		isLumpFirstAdd:true,
		deviceCode:"请输入设备编号",//设备编号
		deviceName:"请输入设备名称",//设备名称
		outTime:"请输入退出时间",//退出时间
		stopTime:"请输入停机间隔",//停机间隔
		remark:"请输入备注",//备注
		day:"请完善停机间隔",
		hour:"请完善停机间隔",
		minute:"请完善停机间隔",
		monthOutCount:"请输入本月此装置退出次数",//本月此装置退出次数(累计值)
	}
	
	NeioConfig.prototype.checkNetWorkList = function(data,type){
		
		let netWorkList = type == "in" ? netWorkInList : netWorkOutList;
		for(let position in netWorkList){
			for(let i in data){
			let mPos = parseInt(i)+1;
				for(let key in data[i]){
					// console.log(position,key)
					if((data[i][key] == undefined || data[i][key] === "") && key == position){
						if(key != "remark" && key != "areaCenterCommand" && key != "isLumpFirst" && key != "isLumpFirstAdd" && key != "deviceInfoId"){
							mui.alert("表单"+mPos+":"+netWorkList[key])
							return false;
						}
					}	
				}
			}
		}
		return true;
	}
	
	//保护压板数据
	// let plateData = [];
	// let plateType ;//投入或退出
	// let plateNewData = [];//涉网设备 List
	// NeioConfig.prototype.setplateData = function(data,plateType,fun){
	// 	plateData = [];
	// 	plateNewData = [];
	// 	plateData = plateData.concat(data);
	// 	plateType = plateType;
	// 	devideCodeCheck(fun,plateType);
	// }
	
	//保护压板非空验证
	// 投入
	let platenIn = {
					isLumpFirst:false,
					isLumpFirstAdd:true,
					plateCode:'请输入保护压板编号',
					plateName:'请输入保护压板名称',
					deviceName:"请输入所属设备名称",
					inCause:"请输入投入事由",
					inTime:"请选择投入时间",
			}
			
	// 退出
	let platenout = {
					isLumpFirst:false,
					isLumpFirstAdd:true,
					plateCode:'请输入保护压板编号',
					plateName:'请输入保护压板名称',
					deviceName:"请输入所属设备名称",
					outCause:"请输入退出事由",
					outTime:"请选择退出时间",
			}
			
	NeioConfig.prototype.checkPlatenList = function(data,type){
		
		let netWorkList = type == "in" ? platenIn : platenout;
		for(let position in netWorkList){
			for(let i in data){
			let mPos = parseInt(i)+1;
				for(let key in data[i]){
					if((data[i][key] == undefined || data[i][key] === "") && key == position){
						if(key != "remark" && key != "areaCenterCommand" && key != "isLumpFirst" && key != "isLumpFirstAdd" && key != "deviceInfoId"){
							mui.alert("表单"+mPos+":"+netWorkList[key])
							return false;
						}
					}	
				}
			}
		}
		return true;
	}
	

	
	//公用Config 用于保存 项目中的配置信息
	let mConfig = {
		URL:{
			//文件上传
			'uploadFile':'/app/common/uploadFile',
			//获取变压器有载调压列表
			'queryTransOperate':"/app/currentEntry/transOperate/queryTransOperate",
			//保存变压器有载调压工单
			'saveOrUpdateTransOperate':"/app/currentEntry/transOperate/saveOrUpdateTransOperate",
			//提交变压器有载调压工单
			'submitTransOperate':"/app/currentEntry/transOperate/submitTransOperate",
			//审核通过
			'approveTransOperate':"/app/currentEntry/transOperate/approveTransOperate",
			//流程退回
			'sendBack':'/app/personWork/sendBack',
			//流程退回-新接口 上面的作废
			'sendBackTransOperate':"/app/currentEntry/transOperate/sendBackTransOperate",
			//通过workId获取有载调压List
			'queryTransInfoByWorkId':"/app/currentEntry/transOperate/queryTransInfoByWorkId",
			//通过transOperateId获取有载调压List
			'queryTransInfoById':'/app/currentEntry/transOperate/queryTransInfoById',
			//流程退回-新接口 上面的作废
			'sendBackTransOperate':"/app/currentEntry/transOperate/sendBackTransOperate",
			//涉网设备投退记录列表
			'queryNetDevice':"/app/currentEntry/neiosNetworkDevice/queryNetDevice",
			//摄网设备投退记录详情
			'queryNetDeviceInfoById':'/app/currentEntry/neiosNetworkDevice/queryNetDeviceInfoById',
			//涉网设备详情——workId获取
			'queryNetDeviceInfoByWorkId':"/app/currentEntry/neiosNetworkDevice/queryNetDeviceInfoByWorkId",
			//涉网设备投入
			'saveOrUpdateNetDevice':'/app/currentEntry/neiosNetworkDevice/saveOrUpdateNetDevice',
			//查找设备编号(根据输入的数字模糊查询)
			'checkDeviceValidate':'/app/currentEntry/neiosNetworkDevice/checkDeviceValidate',
			//保护压板list查询
			'queryPlateOperate':'/app/currentEntry/plateOperate/queryPlateOperate',
			//保护压板保存
			'saveOrUpdatePlateOperate':'/app/currentEntry/plateOperate/saveOrUpdatePlateOperate',
			//保护压板提交
			'submitPlateOperate':'/app/currentEntry/plateOperate/submitPlateOperate',
			//保护压板详情获取
			'queryPlateInfoById':'/app/currentEntry/plateOperate/queryPlateInfoById',
			//根据workId获取保护压板详情
			'queryPlateInfoByWorkId':"/app/currentEntry/plateOperate/queryPlateInfoByWorkId",
			//获取文件列表
			'getFileList':'/app/common/getFileList',
			//保护压板校验
			'checkCodeValidate':'/app/currentEntry/plateOperate/checkCodeValidate',
			//保护压板退回
			'sendBackPlateOperate':'/app/currentEntry/plateOperate/sendBackPlateOperate',
			//保护压板 通过
			'approvePlateOperate':'/app/currentEntry/plateOperate/approvePlateOperate',
			//获取故障列表
			'getFaultTicketByPage':'/app/faultManage/faultNotice/getFaultTicketByPage',
			//查询元器件列表
			'getWorkOrderIdByPage':'/app/faultManage/faultNotice/getWorkOrderIdByPage',
			//获取故障详情
			'getFaultTicketById':'/app/faultManage/faultNotice/getFaultTicketById',
			//手动补录
			'saveOrUpdateFault':'/app/faultManage/faultNotice/saveOrUpdateFault'
		},
		KEYS:{
			TRANSFORMER_CODE_LIST:"transFormerCodeList",//变压器类型码表Key
			PAGE_PARAM : "pageParam",//变压器列表页界面传值
			PAGE_PARAM_TRANSFORM_INFO:"PAGE_PARAM_TRANSFORM_INFO",//进入详情页传值
			NET_WORK_DETAIL:"netWorkDetail",//网络设备投退 从列表页进入到详情页的参数
			DEVOICE:"devoiceParam",//涉网设备投退编辑参数
			PLATENDATA:'platenData',//保护压板参数
			PARTS:"parts",//元器件列表数据
			WORKTYPE:'workType'
		},
		PROCESSINGTYPE : "ProcessingType",//变压器(Key) 处理状态 0 查看详情 1 处理 2 编辑
		TRANSFORMER_TYPE:"TRANS_TYPE",//变压器码表的数据字典编码
	}
	
	$.neioConfig = new NeioConfig()
})(mui)